Helper.totalTrueInputs   A
last analyzed

Complexity

Conditions 5

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 7
dl 0
loc 13
ccs 6
cts 6
cp 1
crap 5
rs 9.3333
c 0
b 0
f 0
1
import InvalidInputError from './InvalidInputError';
2
3
export default class Helper {
4
    static dec2bin(number, propositions) {
5 15
        if (!Number.isInteger(number)) {
6 6
            throw new InvalidInputError(number, 'number isnt a number');
7
        }
8
9 9
        if (!Number.isInteger(propositions)) {
10 4
            throw new InvalidInputError(
11
                propositions,
12
                'propositions isnt a number'
13
            );
14
        }
15
16 5
        const binary = parseInt(number, 10).toString(2);
17
18 5
        return binary.padStart(propositions, '0');
19
    }
20
21
    static totalTrueInputs(row) {
22 133
        if (!Array.isArray(row)) {
23 4
            throw new InvalidInputError(row, 'row isnt an array');
24
        }
25
26 129
        if (row.length < 1) {
27 1
            return 0;
28
        }
29
30 128
        return row.reduce(
31 288
            (accumulator, currentValue) => accumulator + (currentValue ? 1 : 0)
32
        );
33
    }
34
}
35